/*
 * NewBill.java
 *
 * Created on  April 12, 2012, 11:08 PM
 */

package BillManage;
import Check.Check;
import Check.DateChooser;
import CustomerManage.Customer;
import GUI.Main;
import UserManage.Users;
import java.awt.Frame;

import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.MaskFormatter;
/**
 *
 * @author  tiennm
 */
public class NewBill extends javax.swing.JPanel {
     private DefaultComboBoxModel cbmdCustomerName = new DefaultComboBoxModel();
    Customer objCustomer = new Customer();
    private DefaultTableModel modelTableBill = new DefaultTableModel();
    Vector vLoadBillNoDetails = new Vector();
    
    String nameTable = "Bill";
    /** Creates new form NewBill */
    public NewBill() {
        super();
        initComponents();
        Vector vCustomer=new Vector();
        try {
            vCustomer=Customer.getAllCustomer();
            cbmdCustomerName.removeAllElements();
            cbmdCustomerName.addElement("---- Choice Customer ----");

            for(int j=0;j<vCustomer.size();j++) {
                objCustomer=(Customer)vCustomer.get(j);
                cbmdCustomerName.addElement(objCustomer.getcustomerName());
            }
            cboCustomerName.setModel(cbmdCustomerName);
            
            vLoadBillNoDetails = Bills.getAllBillNotDetails();
            this.loadTableBillNotDetails("vBillNotDetails",vLoadBillNoDetails);
            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
    /////////////////////////////////

     //////////////////////////////////
    public boolean checkNewBill(){
        Check c = new Check();
        if(cboCustomerName.getSelectedIndex() == 0){
            JOptionPane.showMessageDialog(this,"Customer not selected !","Create new order",JOptionPane.ERROR_MESSAGE);           
            return false;
        }
        else if(!c.checkDateIn(txfDateStart.getText())){
            JOptionPane.showMessageDialog(this,"Date start invalid !","Create new order",JOptionPane.ERROR_MESSAGE);           
            txfDateStart.setText("");
            txfDateStart.requestFocus();
            return false;
        }
       
        
        else if(!c.checkNumber(txtTaxs.getText()) || txtTaxs.getText().contains("'")){
            JOptionPane.showMessageDialog(this,"Tax invalid !","Create new order",JOptionPane.ERROR_MESSAGE);           
            txtTaxs.setText("");
            txtTaxs.requestFocus();
            return false;
        }
        else if(!c.checkDateIn(txfExpiredTime.getText())){
            JOptionPane.showMessageDialog(this,"Expired invalid !","Create new order",JOptionPane.ERROR_MESSAGE);           
            txfDateStart.setText("");
            txfDateStart.requestFocus();
            return false;
        }else if(java.sql.Date.valueOf(txfDateStart.getText().trim()).compareTo(java.sql.Date.valueOf(txfExpiredTime.getText().trim())) >0){
            JOptionPane.showMessageDialog(this," Date start cannot more than Expired !","Create new order",JOptionPane.ERROR_MESSAGE);           
            txfDateStart.setText("");
            txfDateStart.requestFocus();
            return false;
        }
        return true;
    }
    
     public void loadTableBillNotDetails(String nameTable,Vector vLoad){
        modelTableBill.setNumRows(0);
        Vector columnBill = new Vector();
       // columnBill.addElement("Code");
        columnBill.addElement("billType");
        columnBill.addElement("customerName");
        columnBill.addElement("addressToDeliver");
        columnBill.addElement("dateStart");
        columnBill.addElement("ExpiredTime");
        columnBill.addElement("Tax");
       
        modelTableBill.setColumnIdentifiers(columnBill);
        Bills objBill = new Bills();
        for(int i=0; i< vLoad.size();i++){
            objBill = (Bills) vLoad.get(i);
            Vector rowBill = new Vector();
         //   rowBill.addElement(objBill.getbillCode());
            rowBill.addElement(objBill.getbillType());
            rowBill.addElement(objBill.getcustomerName());
            rowBill.addElement(objBill.getaddressToDeliver());
            rowBill.addElement(objBill.getdateStart());
            rowBill.addElement(objBill.getexpiredTime());
            rowBill.addElement(objBill.gettax());
         
            modelTableBill.addRow(rowBill);
        }
        tableNewBill.setModel(modelTableBill);
    }
    
      public void loadCustomer() throws SQLException{
        Vector vLoadOrder = new Vector();
        Vector vCustomerName=new Vector();
        vCustomerName=Customer.getAllCustomer();
        
        for(int j=0;j<vCustomerName.size();j++) {
            objCustomer=(Customer)vCustomerName.get(j);
            if(cboCustomerName.getSelectedItem().equals(objCustomer.getcustomerName())){
                txaCustomerAddress.setText(objCustomer.getcustomerAddress());
           }
        }
     }
    
     public void AddNewBill() throws SQLException{
        
        if(!this.checkNewBill()){
            return;
        }
        
        int test = 0;
        Bills objBill = new Bills();
        if(radImport.isSelected()==true){
            objBill.setbillType("Purchase");
        }else
            objBill.setbillType("Sale");
        
        Vector vCustomerName=new Vector();
        vCustomerName=Customer.getAllCustomer();
        for(int j=0;j<vCustomerName.size();j++) {
           objCustomer=(Customer)vCustomerName.get(j);
           if(cboCustomerName.getSelectedItem().equals(objCustomer.getcustomerName())){
                objBill.setcustomerCode(objCustomer.getcustomerCode());                
             }           
        } 
        
        objBill.setaddressToDeliver(txaCustomerAddress.getText().trim());
        objBill.setdateStart(txfDateStart.getText().trim());
        objBill.setexpiredTime(txfExpiredTime.getText().trim());
        objBill.settax(Float.parseFloat(txtTaxs.getText().trim())/100);
        
        if(radWaiting.isSelected()==true){
            objBill.setstatus("waitting");
        }else{
            objBill.setstatus("complete");
        }
        
        Vector vlist = new Vector();
        Vector vloadUser = new Vector();
        vlist.addElement(Main.nameLogin);
        vloadUser = Users.getUserCodeForOrders(vlist);
        Users objUser = new Users();
        for(int i=0; i< vloadUser.size();i++){
            objUser = (Users) vloadUser.get(i);
            objBill.setuserCode(objUser.getuserCode());
        }   
        test = Bills.insertBill(objBill);
        if(test == 1){
            JOptionPane.showMessageDialog(this,"Insert Successfully !","Create Bill",JOptionPane.INFORMATION_MESSAGE);
            vLoadBillNoDetails = Bills.getAllBillNotDetails();
            this.loadTableBillNotDetails("vBillNotDetails",vLoadBillNoDetails);
        }else{
            JOptionPane.showMessageDialog(this,"Insert Error !","Create Bill",JOptionPane.ERROR_MESSAGE);
            vLoadBillNoDetails = Bills.getAllBillNotDetails();
            this.loadTableBillNotDetails("vBillNotDetails",vLoadBillNoDetails);
        }
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jpanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cboCustomerName = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txaCustomerAddress = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        radExport = new javax.swing.JRadioButton();
        radImport = new javax.swing.JRadioButton();
        jLabel4 = new javax.swing.JLabel();
        txfDateStart = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        radWaiting = new javax.swing.JRadioButton();
        radComplete = new javax.swing.JRadioButton();
        jLabel7 = new javax.swing.JLabel();
        txtTaxs = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txfExpiredTime = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        btnCreate = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tableNewBill = new javax.swing.JTable();

        jpanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Create Bill", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(0, 102, 102))); // NOI18N

        jLabel1.setText("Customer Name");

        cboCustomerName.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cboCustomerNameItemStateChanged(evt);
            }
        });

        jLabel2.setText("Address");

        txaCustomerAddress.setColumns(20);
        txaCustomerAddress.setRows(5);
        jScrollPane1.setViewportView(txaCustomerAddress);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(106, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel3.setText("Bill Type");

        buttonGroup1.add(radExport);
        radExport.setSelected(true);
        radExport.setText("Sale");
        radExport.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        radExport.setMargin(new java.awt.Insets(0, 0, 0, 0));

        buttonGroup1.add(radImport);
        radImport.setText("Purchase");
        radImport.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        radImport.setMargin(new java.awt.Insets(0, 0, 0, 0));
        radImport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radImportActionPerformed(evt);
            }
        });

        jLabel4.setText("Date Start");

        try {
            txfDateStart = new JFormattedTextField(new MaskFormatter("####-##-##"));
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        txfDateStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txfDateStartActionPerformed(evt);
            }
        });

        jLabel6.setText("Status");

        buttonGroup2.add(radWaiting);
        radWaiting.setSelected(true);
        radWaiting.setText("Waiting");
        radWaiting.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        radWaiting.setMargin(new java.awt.Insets(0, 0, 0, 0));
        radWaiting.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radWaitingActionPerformed(evt);
            }
        });

        buttonGroup2.add(radComplete);
        radComplete.setText("Complete");
        radComplete.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        radComplete.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jLabel7.setText("Tax");

        jLabel8.setText("[%]");

        jLabel9.setText("Expired Time");

        try {
            txfExpiredTime = new JFormattedTextField(new MaskFormatter("####-##-##"));
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        txfExpiredTime.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txfExpiredTimeActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/calendar-date-16x16.png"))); // NOI18N
        jButton1.setText("Date");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/calendar-date-16x16.png"))); // NOI18N
        jButton2.setText("Date");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpanel1Layout = new javax.swing.GroupLayout(jpanel1);
        jpanel1.setLayout(jpanel1Layout);
        jpanel1Layout.setHorizontalGroup(
            jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4))
                .addGap(15, 15, 15)
                .addGroup(jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpanel1Layout.createSequentialGroup()
                        .addGroup(jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cboCustomerName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(122, 122, 122)
                        .addGroup(jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel6)
                            .addComponent(jLabel3))
                        .addGroup(jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpanel1Layout.createSequentialGroup()
                                .addGap(29, 29, 29)
                                .addGroup(jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jpanel1Layout.createSequentialGroup()
                                        .addComponent(radWaiting)
                                        .addGap(29, 29, 29)
                                        .addComponent(radComplete))
                                    .addGroup(jpanel1Layout.createSequentialGroup()
                                        .addComponent(txtTaxs, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel8))
                                    .addGroup(jpanel1Layout.createSequentialGroup()
                                        .addGap(83, 83, 83)
                                        .addComponent(radExport)))
                                .addGap(13, 13, 13))
                            .addGroup(jpanel1Layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(radImport)))
                        .addContainerGap(21, Short.MAX_VALUE))
                    .addGroup(jpanel1Layout.createSequentialGroup()
                        .addComponent(txfDateStart, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1)
                        .addGap(201, 201, 201)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txfExpiredTime, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2)
                        .addContainerGap(24, Short.MAX_VALUE))))
        );
        jpanel1Layout.setVerticalGroup(
            jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanel1Layout.createSequentialGroup()
                .addGroup(jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpanel1Layout.createSequentialGroup()
                        .addGroup(jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(cboCustomerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(12, 12, 12)
                        .addGroup(jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpanel1Layout.createSequentialGroup()
                        .addGroup(jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(radWaiting, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(radComplete))
                        .addGap(18, 18, 18)
                        .addGroup(jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtTaxs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addGap(36, 36, 36)
                        .addGroup(jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(radImport)
                                .addComponent(radExport))
                            .addComponent(jLabel3))))
                .addGap(32, 32, 32)
                .addGroup(jpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txfDateStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1)
                    .addComponent(jLabel9)
                    .addComponent(txfExpiredTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnCreate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/add.png"))); // NOI18N
        btnCreate.setText("Create");
        btnCreate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCreateActionPerformed(evt);
            }
        });

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Bill List", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(0, 102, 102))); // NOI18N

        jScrollPane3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jScrollPane3MouseClicked(evt);
            }
        });

        tableNewBill.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(tableNewBill);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 702, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(623, Short.MAX_VALUE)
                .addComponent(btnCreate)
                .addGap(156, 156, 156))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jpanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(27, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCreate)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(42, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cboCustomerNameItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboCustomerNameItemStateChanged
        try {
// TODO add your handling code here:
            this.loadCustomer();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_cboCustomerNameItemStateChanged

    private void btnCreateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCreateActionPerformed
 
        try{
        this.AddNewBill();
        }
        catch(SQLException ex){
        ex.printStackTrace();
        }
                /*try {
// TODO add your handling code here:
        this.AddNewBill();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
  */
    }//GEN-LAST:event_btnCreateActionPerformed

    private void txfDateStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txfDateStartActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txfDateStartActionPerformed

    private void txfExpiredTimeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txfExpiredTimeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txfExpiredTimeActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  DateChooser dateChooser = new DateChooser((Frame) null, "Select your birthday");
        Date getDate = new Date();
        getDate = dateChooser.select(getDate);
        Date birthday;
        if(getDate== null) {
            birthday = new Date();
            return;
        }
        birthday = getDate;
        SimpleDateFormat formatDate = new SimpleDateFormat("yyyyMMdd");
        txfDateStart.setText(formatDate.format(birthday));
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
DateChooser dateChooser = new DateChooser((Frame) null, "Select your birthday");
        Date getDate = new Date();
        getDate = dateChooser.select(getDate);
        Date birthday;
        if(getDate== null) {
            birthday = new Date();
            return;
        }
        birthday = getDate;
        SimpleDateFormat formatDate = new SimpleDateFormat("yyyyMMdd");
        txfExpiredTime.setText(formatDate.format(birthday));
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jScrollPane3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jScrollPane3MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jScrollPane3MouseClicked

    private void radImportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radImportActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_radImportActionPerformed

    private void radWaitingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radWaitingActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_radWaitingActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCreate;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JComboBox cboCustomerName;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JPanel jpanel1;
    private javax.swing.JRadioButton radComplete;
    private javax.swing.JRadioButton radExport;
    private javax.swing.JRadioButton radImport;
    private javax.swing.JRadioButton radWaiting;
    private javax.swing.JTable tableNewBill;
    private javax.swing.JTextArea txaCustomerAddress;
    private javax.swing.JTextField txfDateStart;
    private javax.swing.JTextField txfExpiredTime;
    private javax.swing.JTextField txtTaxs;
    // End of variables declaration//GEN-END:variables
    
}
